<?php
/**
 * 
 * @todo description of this class
 * 
 * @author Alton Crossley <crossleyframework@nogahidebootstrap.com>
 * @package Crossley Framework
 *  
 * @copyright Copyright (c) 2003-2009, Nogaide BootStrap INC. All rights reserved.
 * @license BSD http://opensource.org/licenses/bsd-license.php
 * @version $Id:$
 * 
 */
class X_Data_Meta_Column
{
    /**
     * name of the column
     *
     * @var string
     */
    public $sName;
    /**
     * data type of the column as used in the create statement
     *
     * @var string
     */
    public $sType;
    /**
     * bind type as used in binding data in PDO
     *
     * @var character
     */
    public $cBindType;
    /**
     * length of data as defined in the create statement
     *
     * @var int
     */
    public $iLength;
    /**
     * can the column be nulled
     *
     * @var bool
     */
    public $bNullable;
    /**
     * is this an unsigned number
     *
     * @var bool
     */
    public $bUnsigned = false;
    /**
     * is this number auto incremented
     *
     * @var bool
     */
    public $bAutoIncrement = false;
    /**
     * the default value of this column
     *
     * @var string
     */
    public $sDefault;
    /**
     * anything we were not able to discern
     *
     * @var string
     */
    public $sExtra;
    
    /**
     * @return bool
     */
    public function getAutoIncrement()
    {
        return $this->bAutoIncrement;
    }
    
    /**
     * @param bool $bAutoIncrement
     */
    public function setAutoIncrement($bAutoIncrement)
    {
        $this->bAutoIncrement = (bool)$bAutoIncrement;
    }
    
    /**
     * @return bool
     */
    public function getNullable()
    {
        return $this->bNullable;
    }
    
    /**
     * @param bool $bNullable
     */
    public function setNullable($bNullable)
    {
        $this->bNullable = (bool)$bNullable;
    }
    
    /**
     * @return bool
     */
    public function getUnsigned()
    {
        return $this->bUnsigned;
    }
    
    /**
     * @param bool $bUnsigned
     */
    public function setUnsigned($bUnsigned)
    {
        $this->bUnsigned = (bool)$bUnsigned;
    }
    
    /**
     * @return character
     */
    public function getBindType()
    {
        return $this->cBindType;
    }
    
    /**
     * @param character $cBindType
     */
    public function setBindType($cBindType)
    {
        $this->cBindType = (string)$cBindType;
    }
    
    /**
     * @return int
     */
    public function getLength()
    {
        return $this->iLength;
    }
    
    /**
     * @param int $iLength
     */
    public function setLength($iLength)
    {
        $this->iLength = (int)$iLength;
    }
    
    /**
     * @return string
     */
    public function getDefault()
    {
        return $this->sDefault;
    }
    
    /**
     * @param string $sDefault
     */
    public function setDefault($sDefault)
    {
        $this->sDefault = (string)$sDefault;
    }
    
    /**
     * @return string
     */
    public function getExtra()
    {
        return $this->sExtra;
    }
    
    /**
     * @param string $sExtra
     */
    public function setExtra($sExtra)
    {
        $this->sExtra = (string)$sExtra;
    }
    
    /**
     * @return string
     */
    public function getName()
    {
        return $this->sName;
    }
    
    /**
     * @param string $sName
     */
    public function setName($sName)
    {
        $this->sName = (string)$sName;
    }
    
    /**
     * @return string
     */
    public function getType()
    {
        return $this->sType;
    }
    
    /**
     * @param string $sType
     */
    public function setType($sType)
    {
        $this->sType = (string)$sType;
    }
    
	/**
     * map array for setting attributes form Array values
     *
     * @var array
     */
    static protected $_aArrayMap = array(
        'name' => 'sName'
        ,'type' => 'sType'
        ,'length' => 'iLength'
        ,'extra' => 'sExtra'
        ,'nullable' => 'bNullable'
        ,'default' => 'sDefalut'
        ,'unsigned' => 'bUnsigned'
        ,'auto_increment' => 'bAutoIncrement'
    );
    

    /**
     * factory to build this class from an array
     *
     * @param Array $aArray
     * @return X_Data_Meta_Column
     */
    static public function fromArray(Array $aArray)
    {
        $sClass = __CLASS__;
        $oNew = new $sClass();
        
        foreach ($aArray as $sKey => $sValue)
        {
            if (array_key_exists($sKey, self::$_aArrayMap))
            {
                $sAttrName = self::$_aArrayMap[$sKey];
                $oNew->$sAttrName = $sValue;
            }
        }
        
        return $oNew;
        
    }

    /**
     * public wrapper for __toArray()
     *
     * @return array
     */
    public function toArray()
    {
        return $this->__toArray();
    }
    
	/**
     * convert the current object to an array
     *
     * @return array
     */
    public function __toArray()
    {
        $a = array();
        foreach (self::$_aArrayMap as $sKey => $sValue)
        {
            $a[$skey] = $this->$sValue;
        }
        
        return $a;
    }
}

